package com.example.allplan.RecyclerAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.example.allplan.JavaBean.BiaoQingLieBiao;
import com.example.allplan.JavaBean.NaoZhongJavaBean;
import com.example.allplan.R;
import com.example.allplan.StaticFangfa.BiaoQingZhuanHuan;

import java.util.ArrayList;
import java.util.zip.Inflater;

public class NaoZhongLieBiaoAdapter extends RecyclerView.Adapter<NaoZhongLieBiaoAdapter.ViewHolder> {
    ArrayList<NaoZhongJavaBean> mlist;
    LayoutInflater mli;
    onItemClickListener mlistener;
    Context mcon;
    public NaoZhongLieBiaoAdapter(ArrayList<NaoZhongJavaBean> mlist, Context mcon, onItemClickListener mlistener) {
        this.mlist = mlist;
        this.mcon=mcon;
        this.mlistener = mlistener;
        this.mli=LayoutInflater.from(mcon);
    }

    public interface onItemClickListener{
        void onXiTongClick(int pos,Context mcon);
        void  onDaoJiShiClick(int pos,Context mcon);
        void ondeleteClick(int pos);
    }
    @Override
    public NaoZhongLieBiaoAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= mli.inflate(R.layout.nao_zhong_ka_pian_layout,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
        holder.mingcheng_textview.setText(mlist.get(holder.getAdapterPosition()).getNao_zhong_ming());
        holder.mgen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mlistener.ondeleteClick(holder.getAdapterPosition());
            }
        });
        holder.naozhong_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mlistener.onXiTongClick(holder.getAdapterPosition(),mcon);
            }
        });
        holder.daojishi_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mlistener.onDaoJiShiClick(holder.getAdapterPosition(),mcon);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        CardView mgen;
        TextView mingcheng_textview;
        Button naozhong_button,daojishi_button;

        public ViewHolder(View itemView) {
            super(itemView);
            mgen=itemView.findViewById(R.id.ka_pian_view);
            mingcheng_textview=itemView.findViewById(R.id.nao_zhong_ming_textview);
            naozhong_button=itemView.findViewById(R.id.she_zhi_xi_tong_nao_zhong);
            daojishi_button=itemView.findViewById(R.id.da_kai_dao_ji_shi);
        }
    }
}
